home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / INTERRUP.SWG / 0007_Int29 Char Capture.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-31  |  3KB  |  102 lines

  1. ==============================================================================
  2.  BBS: -=- Edge of the Century -=-
  3.   To: PERCY WONG                   Date: 03-22-93 (10:19)
  4. From: GAYLE DAVIS                Number: 4475   [140] Pascal
  5. Subj: Capturing Dos Output       Status: Public
  6. ------------------------------------------------------------------------------
  7. PW>-> PW>  EXEC(GETENV(COMSPEC),' \C DIR'); { or whatever it is }
  8. PW>-> >can i then capture each line (or even one line) of the Dir output to
  9.  
  10. Percy or Kerry ??,
  11.  
  12. An elegant  way of accomplishing  your goal  is  to grap INT29.  This is an
  13. UNDOCUMENTED  DOS function,  however, it's  really simple  to use. DOS uses
  14. this to write EVERYTHING to the screen.  The problem is that there is a LOT
  15. of data  output when screen writing  takes place. If you  try to capture to
  16. much you will  need LOTS of memory. However, short  output like your trying
  17. to get is OK.
  18.  
  19. Here is some sample code that will let you capture output :
  20.  
  21.  
  22. {$A+,B-,D+,E+,F-,G+,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V-,X+,Y+}
  23. {$M 4096,0,400000}
  24.  
  25. Uses DOS,Crt;
  26.  
  27. Type
  28.   ISRRegisters =
  29.     record
  30.       case Byte of
  31.         1 : (BP, ES, DS, DI, SI, DX, CX, BX, AX, IP, CS, Flags : Word);
  32.         2 : (j1,j2,j3,j4,j5 : Word; DL, DH, CL, CH, BL, BH, AL, AH : Byte);
  33.     end;
  34.  
  35. CONST
  36.  
  37.   OrigInt29 : Pointer = nil;             {Old int 29 vector}
  38.  
  39. Var
  40.     grab  : Array[1..32768] Of Char;   { this MAY NOT be enough !!!     }
  41.     idx : LongInt;                     { if output EXCEEDS this, might  }
  42.                                        { lock up machine, so be careful }
  43.     S   : String;
  44.     I   : LongInt;
  45.  
  46. { Here is the MAGIC }
  47. procedure Int29(BP : Word); interrupt;
  48.  
  49. var
  50.   Regs : ISRRegisters absolute BP;
  51.  
  52. begin
  53.  
  54.  
  55.  Grab[Idx] := CHAR(Regs.AL);
  56.  Inc(idx);
  57.  
  58.  { WILL LOOSE OUTPUT, BUT BETTER THAN LOCKING MACHINE !!}
  59.  If Idx > SizeOf(Grab) THEN Idx := 1;
  60.  
  61.  ASM
  62.  PopF
  63.  call OrigInt29
  64.  END;
  65.  
  66. end;
  67.  
  68. BEGIN
  69.  
  70.   GetIntVec($29, OrigInt29);
  71.   SetIntVec($29, @Int29);
  72.  
  73.  
  74.   Clrscr;
  75.   Idx := 1;
  76.  
  77.   {Shell to DOS and run your program}
  78.  
  79.   SwapVectors;
  80.   Exec(GetEnv('COMSPEC'), '/c '+ YOURPROGRAM);
  81.   SwapVectors;
  82.  
  83.   { GRAB now contains ALL of our output }
  84.  
  85.   FOR I := 1 TO Idx DO
  86.       BEGIN
  87.       If Grab[i] = #10 Then BEGIN
  88.                            WriteLn(S);
  89.                            S := ''
  90.                            END ELSE If Grab[i] <> #13 THEN S := S + Grab[i];
  91.  
  92.       END;
  93.  
  94.   { ABSOLUTELY MUST BE DONE !! }
  95.   if OrigInt29 <> nil then SetIntVec($29, OrigInt29);
  96.  
  97.  
  98. UtiExprt: To be continued in next message ...
  99. ---
  100.  * T.I.F.S.D.B.(from MD,USA 301-990-6362)
  101.  * PostLink(tm) v1.05  TIFSDBU (#1258) : RelayNet(TM)
  102.